﻿function removeHtmlTag(strx, chop) {
    if (strx.indexOf("<") != -1) {
        var s = strx.split("<");
        for (var i = 0; i < s.length; i++) {
            if (s[i].indexOf(">") != -1) {
                s[i] = s[i].substring(s[i].indexOf(">") + 1, s[i].length)
            }
        }
        strx = s.join("")
    }
    chop = (chop < strx.length - 1) ? chop : strx.length - 2;
    while (strx.charAt(chop - 1) != ' ' && strx.indexOf(' ', chop) != -1) chop++;
    strx = strx.substring(0, chop - 1);
    return strx + ' [...]'
}

function showrecentposts2(e) {
    j = (showRandomImg) ? Math.floor((imgr.length + 1) * Math.random()) : 0;
    img = new Array();
    for (var i = 0; i < numposts2; i++) {
        var f = e.feed.entry[i];
        var g = f.title.$t;
        var h;
        if (i == e.feed.entry.length) break;
        for (var k = 0; k < f.link.length; k++) {
            if (f.link[k].rel == 'alternate') {
                h = f.link[k].href;
                break
            }
        }
        if ("content" in f) {
            var l = f.content.$t
        } else if ("summary" in f) {
            var l = f.summary.$t
        } else var l = "";
        if (j > imgr.length - 1) j = 0;
        img[i] = imgr[j];
        s = l;
        a = s.indexOf("<img");
        b = s.indexOf("src=\"", a);
        c = s.indexOf("\"", b + 5);
        d = s.substr(b + 5, c - b - 5);
        if ((a != -1) && (b != -1) && (c != -1) && (d != "")) img[i] = d;
        if (i == 0) {
            var m = '<div class="folder-topnews fl"><img src="' + img[i] + '" title="' + g + '" class="img-subject fl"><p style="padding-bottom:5px"><a href="' + h + '"><b>' + g + '</b></a></p><p>' + removeHtmlTag(l, summaryPost) + '</p><a href="' + h + '" class="xemthem">Xem thêm <img src="http://lh5.ggpht.com/_CtAentwhdRk/TQTNCBbcRcI/AAAAAAAABVo/P3BXfzjA81c/readmoreicon.png" alt="' + g + '"/></a></div>';
            document.write(m)
        }
        if (i == 1) {
            var m = '<div class="folder-othernews fl"><div class="other-folder fl"><img alt="" class="img-other fl" src="' + img[i] + '" alt="' + g + '"><a href="' + h + '">' + g + '</a></div>';
            document.write(m)
        }
        if (i == 2) {
            var m = '<div class="fl"><ul><li><a href="' + h + '">' + g + '</a></li>';
            document.write(m)
        }
        if ((i > 2) && (i < numposts2 - 1)) {
            var m = '<li><a href="' + h + '">' + g + '</a></li>';
            document.write(m)
        }
        if (i == numposts2 - 1) {
            var m = '<li><a href="' + h + '">' + g + '</a></li></ul></div></div>';
            document.write(m)
        }
        j++
    }
}
document.write("<script src=\""+homepage+"feeds/posts/default/-/"+label+"?max-results="+numposts2+"&orderby=published&alt=json-in-script&callback=showrecentposts2\"><\/script>");